package aatesting;

import java.util.ArrayList;

/*
 * In number theory, a perfect number is a positive integer that is equal 
 * to the sum of its proper positive divisors, that is, 
 * the sum of its positive divisors excluding the number itself (also known as its aliquot sum)
 * The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6.
 * The next perfect number is 28 = 1 + 2 + 4 + 7 + 14
 */
public class IsPerfectNumber {

	public static boolean isPerfectNumber(int num)
	{
		boolean isPerfect = false;
		int sum=1;
		
		if(num<6)return false;
		
		for(int i=2; i<=num/2; i++)
		{
			if(num%i == 0)
			{
				sum += i;
			}
		}
		
		if(sum==num) return true;
		
		return isPerfect;
	}

	public static void main(String args[])
	{
		int range = 10000;
		ArrayList<Integer> perfectNums = new ArrayList<Integer>(); 
		for(int i=0; i<=range;i++)
		{
			if(IsPerfectNumber.isPerfectNumber(i))
				perfectNums.add(i);
		}
		
		System.out.format("Perfect numbers within %s: %s\n",range,perfectNums.toString());
	}
}
